function [savings_EWM] = generate_ewm_results_table_pe_only(covariate,wave,winter_prevuse,SMC,fbase,scaled_ATT,rule,tcost)
% This function summarizes EWM point estimates for EWM rules involving
% baseline consumption only into a summary table

% Inputs:
% (1) covariate: indicates covariate for analysis: 
% minimum of baseline consumption, maximum of baseline consumption, or
% standard deviation of consumption
% (2) wave: indicates whether the output is wave-specific (=3,6,or 7) or
% for the pooled sample (=0) 
% (3) winter_prevuse: indicates whether baseline consumption is calculated 
% as the mean of consumption in winter months (Jan and Feb) or as the mean
% of specified pre-treatment periods
% (4) SMC: =1 use social marginal cost; =0 use retail electricity price
% (5) fbase: string used to indicate the propensity score and baseline
% months specification for output table 
% (6) scaled_ATT: scaled att as a benchmark 
% (7) rule: treatment rule 
% (8) tcost: private marginal cost of implementing the program per household
%  >0 represents cost savings; =0 represents kWh reduction 

% Outputs:
% (1) savings_EWM: summary table of savings 

%% obtain point estimates 
switch winter_prevuse 
    case 1
        s_winter = '_winter';
    case 0
        s_winter = '';
end
if (tcost)>0 
    if (SMC)
        s_cost = 'SMC';
    else
        s_cost = 'PMC';
    end
elseif (tcost)==0
    s_cost='kwh';
end

if rule=="quadrant"
    filename_coefs=sprintf('coef_quadrant_%s_%s%s_wave%1.0f.mat',covariate,s_cost,s_winter,wave);
elseif rule=="cubic"
    filename_coefs=sprintf('coef_cubic_%s_%s%s_wave%1.0f.mat',covariate,s_cost,s_winter,wave);
elseif rule=="onedim"
    filename_coefs=sprintf('coef_onedim_%s_baseline_%s%s_wave%1.0f.mat',covariate,s_cost,s_winter,wave);
end
    file = sprintf('%s_%s',fbase,filename_coefs);
S=load(file);

%extract content of S_quadrant
c_fieldnames = fieldnames(S);
for ifield = 1:length(c_fieldnames)
    field_ = c_fieldnames{ifield};
    eval(sprintf('%s=S.%s;',field_,field_))
end

% obtain scaled att
scaled_att_PE=scaled_ATT;

%% Calculate PE of V(G_hat) for savings and CI for savings 
if rule=="quadrant" || rule=="onedim"
    percent = sum(nw.*in_Ghat)/n;
    savings = sum(gu.*in_Ghat)/n;
elseif rule=="cubic"
    percent = mean(in_Ghat);
    savings = nanmean(g.*in_Ghat)*Yscale;
end

%% Output for table 
savings_EWM=nan(1,4);
savings_EWM=array2table(savings_EWM,'VariableNames',{'Covariates','Share\ treated','Savings\ from\ EWM\ rules','Difference\ in\ savings\ between\ EWM\ RCT'}); 
format short g
savings_EWM.(1) = {covariate};
savings_EWM.(2) =round(percent*100);
savings_EWM.(3) =round(savings,2);
savings_EWM.(4) =round(savings-scaled_att_PE,2);
end

